import { action, makeAutoObservable } from 'mobx';

class Count {
    username: string = '';

    mobile: string = '';

    password: string = '';

    imgpath: string = '';

    alertTip: string = '';

    alertStatus: boolean = false;

    setAlertTip(alertTip: string) {
        this.alertTip = alertTip;
    }

    setAlertStatus(alertStatus: boolean) {
        this.alertStatus = alertStatus;
        if (!alertStatus) {
            this.alertTip = '';
        }
    }

    constructor() {
        makeAutoObservable(this, {
            handleSumit: action.bound,
        });
    }

    setUsername(username: string) {
        this.username = username;
    }

    setMobile(mobile: string) {
        this.mobile = mobile;
    }

    setPassword(password: string) {
        this.password = password;
    }

    async uploadImg(data: any) {
        setTimeout(() => {
            this.imgpath = '';
        }, 2000);
    }

    handleSumit() {
        if (!this.username) {
            this.alertTip = '请填写名称';
            this.alertStatus = true;
        } else if (!this.mobile) {
            this.alertTip = '请填写手机号';
            this.alertStatus = true;
        } else if (!this.password) {
            this.alertTip = '请填写密码';
            this.alertStatus = true;
        } else if (!this.imgpath) {
            this.alertTip = '请上传头像';
            this.alertStatus = true;
        }
    }
}

export default new Count();
